
//会员管理——会员列表
var tab = 1;
var starttime=""; //开始时间
var endtime=""; //结束时间
var pagesize=10;
var pageindex=1;
var sortfild = ""; //排序的关键字
var sortway = ""; //排序：升序、降序
var usertel = getCookie("tel"); //用户电话
var userid = getCookie("user_id"); //用户id
var user_encryptid = getCookie("user_encryptid"); //用户加密id
var cust_encryptid = getCookie("cust_encryptid"); //定制游加密id
console.log("user_encryptid:"+user_encryptid);
console.log("cust_encryptid:"+cust_encryptid);
$(function() {

	if(usertel != "" && usertel != undefined){
		$("#client_name").text(usertel+"客户详情");
	}

	//排序 
	$(".list_sort_tab").click(function(){
		 sortfild=$(this).attr("value"); 
		if($(this).find("i").hasClass("icon_downs")){
			$(this).find("i").removeClass("icon_downs");
			$(this).find("i").addClass("icon_ups");
			sortway="asc";
		}else{
			$(this).find("i").removeClass("icon_ups");
			$(this).find("i").addClass("icon_downs");
			 sortway="desc";
		}
		 //必须要，否则排序则不能调用该方法  使用该句，当点击排序，就同时点击了 第一页的按钮，自动调用分页的效果，
        $("#first_button").click();
	});
	
	//悬浮显示 当宽度小于 文字宽度时，则鼠标移到该内容时，悬浮显示，将文字全部显示出来
	 $(document).on("mouseover",".show_tips",function(){
        if($(this).width()>$(this).parent().width()){
	            layer.tips($(this).html(), $(this), {
	                tips: [1, '#3595CC'],
	                time: 0
	            })
	        }
	});
    $(document).on("mouseout",".show_tips",function(){
        layer.closeAll('tips');
   	});

    //下拉框
    $(document).on('click', ".my_select_ul li", function () {
        $(this).parent().siblings("div").find("span").html($(this).text());
        $(this).parent().siblings("div").find("span").attr("value", $(this).attr("value"));
        if ($(this).parent().siblings("div").find("span").hasClass("business_type_select")) {
            if ($(this).text() == "全部") {
                $(".business_type_select").text("商户类型");
            }
        }else  if ($(this).parent().siblings("div").find("span").hasClass("Shop_type_select")) {
            if ($(this).text() == "全部") {
                $(".Shop_type_select").text("店铺类型");
            }
        }
        //获取数据
        $("#first_button").click();
    })

    //匹配记录 默认调用匹配农家方法
    $("#pick_record").click(function(){
        $("#biuuu_city").show();
        getlist();
    });

    //基本信息
    $("#basic_info").click(function(){
        $("#biuuu_city").hide();
    });

    
	getData();
   
})

//获取数据
function getData(){

    tab =$(".crm_tab").find(".choice_tab_a").attr("value"); //当前选择的排行
    console.log("tab:"+tab);
    if(tab == "2"){
        getlist();
    }else if(tab == "1"){
        getcustomlist();
    }
}

//用户此次定制信息
var cust_type = ""; //定制类型，根据该值，查询相应的表记录
function getcustomlist() {
    if(user_encryptid != "" && cust_encryptid != ""){
        var layLoad=layer.load(2);
        $("#biuuu_city_list").empty();
        $.post('/custom/getcustominfo',{"user_Encryptid":user_encryptid,"cust_Encryptid":cust_encryptid},function(value){
            layer.close(layLoad);
            if(value.status==0 && value.msg == "ok"){
                var list = value.list;
                if(list.length>0){
                    $("#show_username").text(list[0].username);//用户名
                    $("#cust_type").text((list[0].cust_type == null ? "" : getTypeName(list[0].cust_type)));//挑选类型
                    cust_type = list[0].cust_type;

                    $("#user_tel").text(list[0].cust_tel);//电话
                    $("#cName").text(list[0].realName);//姓名
                    $("#ccategory").text((list[0].category == null ? "" : getcategory(list[0].category)));//定制类型
                    $("#cmail").text(list[0].cust_mail);//邮箱
                    $("#croomtype").text(getRoomName(list[0].roomtype));//住房类型
                    $("#cdays").text(list[0].cust_days);//住房类型
                    $("#chufatime").text(list[0].departuretime);//出发时间
                    $("#cWizard").text(getWizardName(list[0].cust_Wizard));//向导需求
                    $("#cdiningl").text(getdininglName(list[0].cust_diningl));//用餐标准
                    $("#chufaArea").text(list[0].chufaArea);//用餐标准
                    $("#cTicket").text((list[0].cust_Ticket == null ? "" : getTicket(list[0].cust_Ticket)) );//门票

                    var str = list[0].pricebudget;
                     str = str.replace(new RegExp(/,/g,'gm'),'-');//逗号替换成-
                    $("#cpricebudget").text("￥"+str+"元");//人均预算

                    $("#cdestination").text(list[0].destination);//目的地
                    $("#ctime").text(list[0].createtime);//定制时间
                    $("#custpaly").text(list[0].cust_paly);//游玩类型
                    $("#cplayNum").text(list[0].totalnum+"(总人数)，"+list[0].chilanum+"(儿童数)，"+list[0].oldnum+"(老人)");//游玩人数
                    $("#capplicatName").text(list[0].applicatName);//申请人
                    $("#cdataSources").text(getdataSources(list[0].dataSources));//数据来源
                    $("#CompanyName").text(list[0].CompanyName);//匹配农家/景区
                    $("#cother").text(list[0].other);//其他需求
                }
            }else{
                if(value.msg==null||value.msg==""){
                    layer.alert("接口出现错误！", {icon: 2})
                }else{
                    layer.alert(value.msg, {icon: 2})
                }
            }
        })
    }else {
        layer.alert("user_encryptid,cust_encryptid不能为空！",{icon:0});
    }
}

//挑选类型
function getTypeName(type) {
    if (type != ""){
        if(type == "1"){
            return "挑选农家"
        }else if(type == "2"){
            return "挑选景区"
        }
        return "";
    }
    return "";
}

//定制类型
function getcategory(category) {
    if (category != ""){
        if(category == "1"){
            return "私人定制";
        }else if(category == "2"){
            return "团队定制";
        }
        return "";
    }
    return "";
}

//住宿类型
function getRoomName(roomtype) {
	if (roomtype != ""){
		if(roomtype == "0"){
			return "不住宿";
		}else if(roomtype == "1"){
            return "经济型";
        }else if(roomtype == "2"){
            return "豪华型";
        }
        return "";
	}
	return "";
}

//向导需求
function getWizardName(Wizard) {
    if (Wizard != ""){
        if(Wizard == "0"){
            return "自行安排";
        }else if(Wizard == "1"){
            return "导游";
        }else if(Wizard == "2"){
            return "领队";
        }
        return "";
    }
    return "";
}

//用餐标准
function getdininglName(diningl) {
    if (diningl != ""){
        if(diningl == "0"){
            return "自行安排";
        }else if(diningl == "5"){
            return "3-5人桌";
        }else if(diningl == "8"){
            return "5-8人桌";
        }else if(diningl == "10"){
            return "9-10人桌";
        }else if(diningl == "12"){
            return "10-12人桌";
        }
        return "";
    }
    return "";
}

//数据来源
function getdataSources(dataSources) {
    if (dataSources != ""){
        if(dataSources == "0"){
            return "管理系统"
        }else if(dataSources == "1"){
            return "前端官网"
        }
        return "";
    }
    return "";
}

//门票
function getTicket(ticket) {
    if (ticket != ""){
        if(ticket == "0"){
            return "不需要"
        }else if(ticket == "1"){
            return "需要"
        }
        return "";
    }
    return "";
}




/***************************-----匹配记录数据列表------*************************/
function getlist() {

    if(cust_type == "1"){
        //农家
        $("#consume_th").text("人均预算");
    }else if(cust_type == "2"){
        //景区
        $("#consume_th").text("门票");
    }
    if(cust_type != ""){
        var pagesize = $("#selectPageSize1").text();
        var pageindex = $("#currentPage").text();
        var shoptype = $("#Shop_type_name").attr("value");//店铺类型
        // var business_type = $("#business_type_name").attr("value");//商户类型
        var layLoad=layer.load(2);
        $("#biuuu_city_list").empty();
        $.post('/custom/getcustomAnduserlist', {
            "pagesize": pagesize,
            "pageindex": pageindex,
            "sortfild": sortfild,
            "sortway": sortway,
            "shoptype": shoptype,
            "user_encryptId":user_encryptid,
            "cust_encryptId":cust_encryptid,
            "business_type":"",
            "cust_type":cust_type
        }, function (value) {
            layer.close(layLoad);
            if(value.status==0 && value.msg == "ok"){
                var list=value.list;
                var shoplist = value.shopTypelist;
                var pagecount=value.pagecount;
                var recordcount=value.recordcount;
                $("#totalSize").html(recordcount);
                $("#totalPage").html(pagecount);

                //店铺类型
                if (shoplist.length>0){
                    var str = "";
                    for (var i=0;i<shoplist.length;i++){
                        str += "<li value='"+ shoplist[i].shopType_encryptId +"'><a href='javascript:void(0)'><span class='show_tips'>"+ shoplist[i].shopTypeName +"</span></a></li>";
                    }
                    if(str != ""){
                        var ul_str = "<li value=''><a href='javascript:void(0);'><span class='show_tips'>全部</span></a></li>"+str;
                    }
                    $(".Shop_Mertype").html(ul_str);
                }

                if(list.length==0){
                    $("#biuuu_city_list").prepend("<tr class=\"iframe_tr iframe_bg\"><td colspan=\"14\" style=\"width:1126px;text-align:center;\">暂无数据</td></tr>");
                }else{
                    var htm="";
                    for(var i=0;i<list.length;i++){
                        htm+="<tr>";
                        htm+="<td><span class='show_tips'>"+(list[i].shopTypeName == null ? "" :list[i].shopTypeName)+"</span></td>";
                        htm+="<td><span class='show_tips'>"+(list[i].CompanyName == null ? "" :list[i].CompanyName)+"</span></td>";
                        htm+="<td><span class='show_tips'>"+(list[i].Legal == null ? "" :list[i].Legal)+"</span></td>";
                        htm+="<td><span class='show_tips'>"+(list[i].tel == null ? "" :list[i].tel)+"</span></td>";
                        htm+="<td><span class='show_tips'>"+(list[i].city == null ? "" :list[i].city)+"</span></td>";
                        htm+="<td><span class='show_tips'>"+(list[i].address == null ? "" :list[i].address)+"</span></td>";
                        htm+="<td><span class='show_tips'>"+(list[i].Intr_info == null ? "" : list[i].Intr_info)+"</span></td>";

                        htm+="<td><span class='show_tips'>"+(list[i].consume == null ? "" :list[i].consume+"元起")+"</span></td>";

                        htm+="<td><span class='show_tips'>"+(list[i].playtype == null ? "" :list[i].playtype)+"</span></td>";
                        htm+="<td><span class='show_tips'>"+(list[i].createtime == null ? "" :list[i].createtime)+"</span></td>";

                        htm += "<td class='td-manage'>";
                        htm += "<a href=\"javascript:void(0)\" onclick=\"question_details('"+list[i].business_encryptId+"','"+list[i].shop_encryptId+"','"+list[i].businessTypeid+"')\">详情</a></div>";
                        htm += "</td>";

                        htm+="</tr>";
                    }
                    $("#biuuu_city_list").html(htm);

                }
            }else{
                if(value.msg==null||value.msg==""){
                    layer.alert("接口出现错误！", {icon: 2})
                }else{
                    layer.alert(value.msg, {icon: 2})
                }
            }
        })
    }else {
        layer.alert("cust_type不能为空！",{icon:2});
    }
}

//挑选类型
function gettypeName(type) {
    if (type != ""){
        if(type == "1"){
            return "挑选农家"
        }else if(type == "2"){
            return "挑选景区"
        }
        return "";
    }
    return "";
}

//根据商户类型id，返回商户类型名称
function getBusinessTypeName(business_type) {
    if (business_type != "" && business_type!=null){
        if(business_type == "1"){
            return "农家乐";
        }else if(business_type == "2"){
            return "旅游景区";
        }
    }else {
        return "";
    }
}


//点击详情 - 跳转商家详情信息页面（应判断用户提交的是挑选农家，还旅游景区）
function question_details(business_encryptId,shop_encryptId,businessTypeid){
    setcookie("business_encryptId",business_encryptId,1,"/");//商家加密id
    setcookie("shop_encryptId",shop_encryptId,1,"/"); //店铺加密id
    if(businessTypeid == "1"){
        var size = "merchant/merchant_information_new.html".length;
        window.parent.addTab_father("农家乐商家详情", "merchant/merchant_information_new.html", size);
    }else if(businessTypeid == "2"){
        var size = "tourist/tour_info_new.html".length;
        window.parent.addTab_father("景区商家详情", "tourist/tour_info_new.html", size);
    }
}



//获取农家乐商户类型
function getAllfarmMertype() {
    $("#farm_Mertype").html("");
    $.post('/farmMerType/getAllfarmMertype', {}, function (data) {
        if (data.status == 0 && data.msg == 'ok') {
            var list = data.list;
            var str = "";
            if(list.length>0){
                for(var i=0;i<list.length;i++){
                    str += "<li encryptId='"+list[i].encryptId+"' value='"+list[i].title+"'><a href='javascript:void(0);'><span class='show_tips'> "+list[i].title+"</span></a></li>";
                }
                if(str != ""){
                    str = "<li encryptId='' value=''><a href='javascript:void(0);'><span class='show_tips'>全部</span></a></li>"+str;
                }
                $(".farm_Mertype").html(str);
            }
        } else {
            if(data.msg==null||data.msg==""){
                layer.alert("接口出现错误！", {icon: 2})
            }else{
                layer.alert(data.msg, {icon: 2})
            }
        }
    })
}

//获取景区商户类型
function getAllSerMertype() {
    $("#tour_Mertype").html("");
    $.post('/SceMerType/getAllSerMertype', {}, function (data) {
        if (data.status == 0 && data.msg == 'ok') {
            var list = data.list;
            var str = "";
            if(list.length>0){
                for(var i=0;i<list.length;i++){
                    str += "<li encryptId='"+list[i].encryptId+"' value='"+list[i].title+"'><a href='javascript:void(0);'><span class='show_tips'>"+list[i].title+"</span></a></li>";
                }
                if(str != ""){
                    str = "<li encryptId='' value=''><a href='javascript:void(0);'><span class='show_tips'>全部</span></a></li>"+str;
                }
                $(".tour_Mertype").html(str);
            }
        } else {
            if(data.msg==null||data.msg==""){
                layer.alert("接口出现错误！", {icon: 2})
            }else{
                layer.alert(data.msg, {icon: 2})
            }
        }
    })
}
